package com.example.zhu.controller.room;

import com.example.zhu.Mapper.RoomMapper;
import com.example.zhu.VO.RoomVo.RoomVO;
import com.example.zhu.dto.Employee;
import com.example.zhu.dto.Reply;
import com.example.zhu.service.IRoomService;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/room")
@Slf4j
public class RoomController {
    @Autowired
    IRoomService roomService;
    @Autowired
    RoomMapper roomMapper;
    @PostMapping("/getAllList")
    public Reply<List<RoomVO>> getAllList(@RequestBody RoomVO roomVO){
        return Reply.success(roomService.getAllList(roomVO));
    }
    @GetMapping("/floor")
    public Reply getFloor() {
        return Reply.success(roomService.getFloor());
    }
    @PostMapping("/All")
    public Reply<List<RoomVO>> getAllList(){
        List<RoomVO> roomVOS = roomMapper.selectAll();
        return Reply.success(roomVOS);
    }
    @PostMapping("/add")
    public Reply add(@RequestBody RoomVO roomVO){
        if(roomVO==null){
            return Reply.failed();
        }
        roomMapper.insert(roomVO);
        return Reply.success();
    }
    @PostMapping("/modify")
    public Reply modify(@RequestBody RoomVO roomVO){
        if(roomVO==null){
            return Reply.failed();
        }
        roomMapper.updata(roomVO);
        return Reply.success();
    }
    @GetMapping("/delete/{id}")
    public Reply  delete(@PathVariable(name = "id") String id){
        roomMapper.deleteById(id);
        return Reply.success();
    }



}


